<#include "../imports/header_dialog.ftl"/>
<#-- 确认是编辑还是新增 -->
<#if (data.data.id > 0)!false >
    <#assign isEdit=true/>
<#else>
    <#assign isEdit=false/>
</#if>
<div style="margin: 20px 20px 20px -20px;">
    <form class="layui-form" id="BMS-dialogForm" action="">
    <#if isEdit>
        <input type="hidden" name="id" value="${data.data.id}"/>
    </#if>
        <div class="layui-form-item">
            <label class="layui-form-label">分组</label>
            <div class="layui-input-block">
                <select name="groupid" lay-verify="required">
                    <option value="">选择所属分组</option>
                <#list data.groups as group>
                    <option <#if (data.data.groupid == group.id)!false >selected</#if>
                            value="${group.id}">${group.name}</option>
                </#list>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" value="${(data.data.name)!''}" lay-verify="required" required
                       autocomplete="off"
                       class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">URL</label>
            <div class="layui-input-block">
                <input type="text" name="actionurl" value="${(data.data.actionurl)!''}" lay-verify="required|" required
                       autocomplete="off" lay-filter="urlTextHandler" class="layui-input" placeholder="例：group/list"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">导航</label>
            <div class="layui-input-block">
            <#-- 默认为正常状态，所以这里判断 data.data.status 为空，默认为1 -->
                <input type="checkbox" <#if (data.data.isnav > 0)!false >checked</#if>
                       name="isnav" lay-skin="switch" lay-filter="isnav"
                       value="1" lay-text="是|否">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标签ID</label>
            <div class="layui-input-block">
            <#-- 默认为正常状态，所以这里判断 data.data.status 为空，默认为1 -->
                <input type="text" name="rel" value="${(data.data.rel)!''}" lay-verify="required" required
                       autocomplete="off"
                       class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" value="${(data.data.sort?c)!''}" required lay-verify="number"
                       autocomplete="off"
                       class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
            <#-- 默认为正常状态，所以这里判断 data.data.status 为空，默认为1 -->
                <input type="checkbox" <#if (data.data.status > 0)!true >checked</#if> name="status" lay-skin="switch"
                       value="1" data-off-value="0" lay-text="正常|锁定">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="BMS-dialogFormFilter">立即提交</button>
            </div>
        </div>
    </form>
</div>
<script>

    var urlTextFilter = "BMS-textURL";

    var $, form, $formElem;
    layui.use(['jquery', 'form', 'bmsajax', 'bmsform'], function () {
    var submitUrl =
    <#if isEdit >parent.layui.bmstable.config.elems.editUrl
    <#else>parent.layui.bmstable.config.elems.addUrl</#if>;
        form = layui.form;
        $ = layui.$;
        var bmsform = layui.bmsform;

        var $formElem = $('#' + bmsform.config.elems.formId);
        /**
         * form渲染，
         * @param1 第一个参数为配置，
         * @param2 第二个参数为自定义事件方法，由元素的 lay-event 确定
         * @param3 第三个参数对象为自定义的验证，可以为方法（返回有值则验证不能过，且返回值作为提示信息）,
         *          可以为数组，数组元素0为正则，元素1为验证不能过提示信息
         */
        bmsform.render({
            submitUrl: submitUrl
        }, {}, {})
    })
</script>

<#include "../imports/footer_dialog.ftl"/>